package cn.cloudreal.cbms.accrual.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cn.cloudreal.cbms.accrual.dao.AccrualDao;
import cn.cloudreal.cbms.common.util.PageBean;
import cn.cloudreal.cbms.vo.ContractAccrual;
import cn.cloudreal.cbms.vo.ItemAccrual;


public class AccrualDaoImpl extends SqlMapClientDaoSupport implements AccrualDao{
	
	private final String GET_TOTAL_ACCRUAL_LIST = "accrual.getTotalAccrualList";
	private final String GET_CONTRACT_ACCRUAL_LIST = "accrual.getContractAccrualList";
	private final String GET_TOTAL_ACCRUAL_COUNT = "accrual.getTotalAccrualCount";
	private final String GET_CONTRACT_ACCRUAL_COUNT = "accrual.getContractAccrualCount";
	
	 /** 日志工具类实例 */
    private static final Logger log = Logger.getLogger(AccrualDaoImpl.class);
    
	@SuppressWarnings("unchecked")
	public List<ItemAccrual> getTotalAccrualList(Map condition, PageBean page) {
		// 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter AccrualDaoImpl getTotalAccrualList() method, return List<ItemAccrual>");
        }
        
		List<ItemAccrual> itemAccruals = null;

		// 总记录数不为零才查询
        if (page.getTotalRecords() != 0)
        {
    		condition.put("i_starid", (page.getPageNo()-1) * page.getPageSize());
    		condition.put("i_endid", (page.getPageNo()-1) * page.getPageSize() + page.getPageSize());
        	// 查询
        	itemAccruals = getSqlMapClientTemplate().queryForList(GET_TOTAL_ACCRUAL_LIST, condition);
        }
        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit AccrualDaoImpl getTotalAccrualList() method, return List<ItemAccrual>");
        }
        return itemAccruals;
	}


	public List<ContractAccrual> getContractAccrualList(Map condition,
			PageBean page) {
		// 打印进入方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Enter AccrualDaoImpl getContractAccrualList() method, return List<ContractAccrual>");
        }
        
		List<ContractAccrual> contractAccruals = null;

		// 总记录数不为零才查询
        if (page.getTotalRecords() != 0)
        {
        	condition.put("i_starid", (page.getPageNo()-1) * page.getPageSize());
    		condition.put("i_endid", (page.getPageNo()-1) * page.getPageSize() + page.getPageSize());
            // 查询
        	contractAccruals = getSqlMapClientTemplate().queryForList(GET_CONTRACT_ACCRUAL_LIST, condition);
        }
        // 打印退出方法体日志
        if (log.isInfoEnabled())
        {
            log.info("Exit AccrualDaoImpl getContractAccrualList() method, return List<ContractAccrual>");
        }
        return contractAccruals;
	}


	public int getTotalAccrualCount(Map condition) 
	{
		Object count = getSqlMapClientTemplate().queryForObject(GET_TOTAL_ACCRUAL_COUNT, condition);
		return count == null ? 0 : (Integer)count;
	}
	
	public int getContractAccrualCount(Map condition) 
	{
		Object count = getSqlMapClientTemplate().queryForObject(GET_CONTRACT_ACCRUAL_COUNT, condition);
		return count == null ? 0 : (Integer)count;
	}
	

}
